﻿<?php

/**
 * @author Nguyen Xuan Hong
 * @copyright 2010
 */

require_once("includes/class.tbl.php");
require_once("includes/subject.tbl.php");
require_once("includes/lesson.tbl.php");

require_once("viewinfo.php");

$branch_id = $_REQUEST["branch"];
if($branch_id > 0)
{
	$class_id = $_REQUEST["class"];
	$subject_id = $_REQUEST["subject"];
	$id = $_REQUEST["id"];
	
	if($id > 0)
	{
		$pClsLesson = new clsLessonTable($id);
		$title = $pClsLesson->value('title');
		$content = $pClsLesson->value('content');
		$attach = $pClsLesson->value('attach');
		$listlesson = $pClsLesson->listobj($branch_id, $class_id, $subject_id);
		$arr_link = array();
		foreach($listlesson as $pClsLesson)
		{
			if($pClsLesson->value('id') != $id)
			{
				$arr_link[$pClsLesson->value('title')] = "?page=lesson&branch=".$branch_id."&class=".$class_id."&subject=".$subject_id."&id=".$pClsLesson->value('id');
			}
		}
		$pClsSubject = new clsSubjectTable($subject_id);
		view_info_with_attach($title, $content, $attach, "Các bài học cùng chủ đề ".$pClsSubject->value("name"), $arr_link );
	}
	else
	{
		if($class_id > 0)
		{
			if($subject_id > 0)
			{
				$pClsSubject = new clsSubjectTable($subject_id);
				$title = "Các bài học của bé ".$pClsClass->value("name");
				$first = false;
				
				$pClsLesson = new clsLessonTable();
				$listlesson = $pClsLesson->listobj($branch_id, $class_id, $subject_id);
				$arr_link = array();
				foreach($listlesson as $pClsLesson)
				{
					if(!$first)
					{
						$title = $pClsLesson->value('title');
						$content = $pClsLesson->value('content');
						$attach = $pClsLesson->value('attach');
						$first = true;	
					}
					else
					{
						$arr_link[$pClsLesson->value('title')] = "?page=lesson&branch=".$branch_id."&class=".$class_id."&subject=".$subject_id."&id=".$pClsLesson->value('id');
					}
				}
				view_info_with_attach($title, $content, $attach, "Các bài học cùng chủ đề ".$pClsSubject->value("name"), $arr_link );
			}
			else
			{
				$pClsClass = new clsClassTable($class_id);
				$pClsSubject = new clsSubjectTable();
				$listSubject = $pClsSubject->listobj();
				$pClsLesson = new clsLessonTable();
				$title = "Các bài học của bé ".$pClsClass->value("name");
				$index = 1;
				if($listSubject)
				{
					foreach($listSubject as $pClsSubject)
					{
						$listlesson = $pClsLesson->listobj($branch_id, $class_id, $pClsSubject->value('id'));
						if(count($listlesson) > 0)
						{
							$arr_subject[$index] = $pClsSubject;
							$index ++;
						}
					}
				}
				view_list_lesson_subject($title, $arr_subject, $branch_id, $class_id);
			}
		}
		else
		{
			$pClsClass = new clsClassTable();
			$listclass = $pClsClass->listobj();
			$pClsLesson = new clsLessonTable();
			$title = "Các bài học của bé";
			$index = 1;
			if($listclass)
			{
				foreach($listclass as $pClsClass)
				{
					$listlesson = $pClsLesson->listobjbyclass($branch_id, $pClsClass->value('id'));
					if(count($listlesson) > 0)
					{
						$arr_class[$index] = $pClsClass;
						$index ++;
					}
				}
			}
			view_list_lesson_class($title, $arr_class, $branch_id);
		}
	}
}
?>